package com.xk.cart.controller;

import com.xk.cart.pojo.Cart;
import com.xk.cart.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class CartController {
    @Autowired
    private CartService cartService;

    /**
     * 购物车新增功能
     * @param cart
     * @return
     */
    @PostMapping
    public ResponseEntity<Void> addCart(@RequestBody Cart cart){

        cartService.addCart(cart);
        return ResponseEntity.status(HttpStatus.CREATED).build();

    }
    /**
     * 查询购物车列表
     */
    @GetMapping("list")
    public ResponseEntity<List<Cart>> queryCartList(){

        return ResponseEntity.ok(cartService.queryCartList());
    }

    /**
     * 删除购物车中的商品
     * @param
     * @return
     */
    @DeleteMapping("{skuId}")
    public ResponseEntity<Void> delCartBuySkuId(@PathVariable("skuId") String skuId){

        cartService.delCartBuySkuId(skuId);
        return ResponseEntity.ok().build();

    }
    /**
     * 修改购物车中商品的数量
     * @param skuId
     * @param num
     * @return
     */
    @PutMapping
    public ResponseEntity updateCartNum(@RequestParam("id") String skuId,@RequestParam("num") String num){
        cartService.updateCartNum(skuId,num);
        return ResponseEntity.ok().build();


    }


}
